#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
交易 - 退款申请功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))

from examples.base_example import BaseExample
from jlpay.services.trans.refunds.refunds_service import RefundsService
from jlpay.model.trans.refunds.refunds import RefundsRequest


class RefundsExample(BaseExample):
    """退款申请示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.trans.refunds.refunds")
        self.service = RefundsService(self.config)
    
    def build_refunds_request(self):
        """
        构建退款申请请求
        
        Returns:
            RefundsRequest实例
        """
        request = RefundsRequest()
        request.set_mch_id("849584358120018")
        request.set_out_trade_no("20250318500005Test")
        request.set_ori_out_trade_no("20250318100005Test")
        #request.set_ori_transaction_id("80011557201909171853011568")
        request.set_total_fee("1")
        request.set_remark("测试退款申请")
        request.set_mch_create_ip("127.0.0.1")
        request.set_longitude("116.397128")
        request.set_latitude("39.916527")
        request.set_notify_url("http://172.20.20.85:38001/jlpay/refunds/notify")
        return request
    
    def refunds_demo(self):
        """退款申请示例"""
        self.logger.info("开始执行退款申请示例")
        
        # 构建请求
        request = self.build_refunds_request()
        
        # 发送请求并处理响应
        self.send_request_and_handle_response(
            self.service.refunds, 
            "退款申请",
            request
        )
        
        self.logger.info("退款申请示例执行完毕")


def main():
    """主函数"""
    example = RefundsExample()
    example.refunds_demo()


if __name__ == "__main__":
    main() 